package com.laowang.project.system.controller;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.laowang.common.utils.SecurityUtils;
import com.laowang.framework.web.page.TableDataInfoMy;
import com.laowang.project.system.domain.TbAccountDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.UserPointLog;
import com.laowang.project.system.service.UserPointLogService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 用户积分变动记录Controller
 *
 * @author laowang
 * @date 2023-01-05
 */
@Api(tags = "用户积分变动记录接口")
@RestController
@RequestMapping("/pointLog")
public class UserPointLogController extends BaseController {
    @Autowired
    private UserPointLogService userPointLogService;

    /**
     * 查询用户积分变动记录列表
     */
    @ApiOperation(value = "小程序端 查询用户积分变动记录列表",notes = "")
    @GetMapping("/listDetail")
    public TableDataInfoMy listDetail(UserPointLog userPointLog) {
        PageHelper.startPage(userPointLog.getPageNum(),userPointLog.getPageSize());
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        userPointLog.setUserId(mid);
        List<UserPointLog> list = userPointLogService.selectUserPointLogList(userPointLog);
        return getDataTableMy(list);
    }




    /**
     * 查询用户积分变动记录列表
     */
    @ApiOperation(value = "查询用户积分变动记录列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:pointLog:list')")
    @GetMapping("/list")
        public TableDataInfo list(UserPointLog userPointLog) {
        startPage();
        List<UserPointLog> list = userPointLogService.selectUserPointLogList(userPointLog);
        return getDataTable(list);
    }

    /**
     * 导出用户积分变动记录列表
     */
    @ApiOperation(value = "导出用户积分变动记录列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:pointLog:export')")
    @Log(title = "用户积分变动记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserPointLog userPointLog) {
        List<UserPointLog> list = userPointLogService.selectUserPointLogList(userPointLog);
        ExcelUtil<UserPointLog> util = new ExcelUtil<UserPointLog>(UserPointLog.class);
        return util.exportExcel(list, "pointLog");
    }

    /**
     * 获取用户积分变动记录详细信息
     */
    @ApiOperation(value = "获取用户积分变动记录详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:pointLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(userPointLogService.selectUserPointLogById(id));
    }

    /**
     * 新增用户积分变动记录
     */
    @ApiOperation(value = "新增用户积分变动记录",notes = "")
    @PreAuthorize("@ss.hasPermi('my:pointLog:add')")
    @Log(title = "用户积分变动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPointLog userPointLog) {
        return toAjax(userPointLogService.insertUserPointLog(userPointLog));
    }

    /**
     * 修改用户积分变动记录
     */
    @ApiOperation(value = "修改用户积分变动记录",notes = "")
    @PreAuthorize("@ss.hasPermi('my:pointLog:edit')")
    @Log(title = "用户积分变动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPointLog userPointLog) {
        return toAjax(userPointLogService.updateUserPointLog(userPointLog));
    }

    /**
     * 删除用户积分变动记录
     */
    @ApiOperation(value = "删除用户积分变动记录",notes = "")
    @PreAuthorize("@ss.hasPermi('my:pointLog:remove')")
    @Log(title = "用户积分变动记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userPointLogService.deleteUserPointLogByIds(ids));
    }
}
